<?php
class TicketAction extends IntesysAction {
	public function insert(){
        if(IS_POST){
            $_POST['site_id'] = (int)__SITEID__;
            $_POST['time']=strtotime($_POST['date']);
            $_POST['giver_id']=session(C('USER_AUTH_KEY'));
            //循环遍历所有员工添加数据
            $memberid=explode(",",$_POST['memberid']);
            foreach($memberid as $val){
                if(trim($val)==''){continue;}
                $_POST['member_id']=(int)$val;
                $data='';
                if ($this->dao->create($data)) {
                    $result = $this->dao->add();
                    if (false !== $result) {
                        $this->insert_data = $this->dao->where(array('id' => $result))->find();
                    } else {
                        $this->error($this->dao->getError());
                    }
                } else {
                    $this->error($this->dao->getError());
                }
            } 
            $this->success('操作成功', U('Intesys/' . MODULE_NAME . '/index')); 
        }
	}
	public function getMemberGroup(){
		$data=M('class_view')->where(['class'=>'member'])->getField('value');
		$members=D('Member')->getallgroupmember2();
		$this->assign('memberlist',$members);
		$this->initView();
		$result=$this->fetch('',$data);
		die(json_encode(['statu'=>1,'result'=>$result]));
	}
	public function getTask(){
		import("@.ORG.Task.Task");
		$this->initView();
		$task=new Task();
		echo(json_encode([$task->selectall(['id'=>1])]));
	}
	public function update(){
		if($this->_get('id')){
            $_POST['id']=$this->_get('id');
			$_POST['time']=strtotime($_POST['date']);
			parent::update();
		}
	}
	public function delete(){
		if($this->_get('id')){
			parent::delete();
		}
	}
	//奖票页面
	public function ticketList(){
		$this->listmap='member_id='.$this->UserInfo;
		$this->pagesize=6;
		$this->listCount=(int)$this->dao->where($this->listmap)->sum('number');
		//查找申请数量
		$this->applycount = M('Mission') -> where(array('member_id' => $this->memberInfo['id'], 'site_id' => __SITEID__, 'form_id' => 0)) -> count();
		//查找申请数量
		$this->applypasscount = M('Mission') -> where(array('member_id' => $this->memberInfo['id'], 'site_id' => __SITEID__, 'form_id' => 0, 'state' => 3)) -> count();
		parent::_list();
		$this->display();	
	}
}

